<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<% String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>编辑处置收款表信息</title>
<jsp:include page="../../import.jsp" flush="true" />
<jsp:include page="../assParking/assParkCommon.jsp" flush="true" /><!-- 时间格式转换 -->
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<form id="recAmtInfo">
				<div class="fieldset1 tabel_col clearFix">
					<div class="fieldBox col_50 Hide">
						<div class="label">数据类型</div>
						<div class="field">
							<select name="dataTypeCd" id="dataTypeCd" validate="{required:true}">
								<c:forEach items="${dataTypeCdList}" var="item">
									<c:if test='${recAmtVo.dataTypeCd ==item.code}'>  
										<option value="${item.code }" selected="selected" >${item.codeNm }</option>
									</c:if>
									<c:if test='${recAmtVo.dataTypeCd !=item.code}'>  
										<option value="${item.code }" >${item.codeNm }</option>
									</c:if>
								</c:forEach>
							</select>
							<span class="requiredSymbol">*</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">银行信息</div>
						<div class="field">
							<input name="payerBankNm" id="payerBankNm" type="text" class="ui-textbox" value="${recAmtVo.payerBankNm }" validate="{required:true}">
							<span class="requiredSymbol">*</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">账号信息</div>
						<div class="field">
							<input name="payerAccNo" id="payerAccNo" type="text" class="ui-textbox" value="${recAmtVo.payerAccNo }" validate="{required:true}">
							<span class="requiredSymbol">*</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">付款方名称</div>
						<div class="field">
							<input name="payerAccNm" id="payerAccNm" type="text" class="ui-textbox" value="${recAmtVo.payerAccNm }" validate="{required:true}">
							<span class="requiredSymbol">*</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">付款金额(元)</div>
						<div class="field">
							<input name="payAmt" id="payAmt" type="text" class="ui-textbox" value="${recAmtVo.payAmt /100}" validate="{required:true}">
							<span class="requiredSymbol">*</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">付款时间</div>
						<div class="field">
							<input name="payTm" id="payTm" type="text" class="ui-datepicker" value="" validate="{required:false}">
							<span class="requiredSymbol">*</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label"></div>
						<div class="field"></div>
					</div>
					<div class="fieldBox col_50 cwqr">
						<div class="label">到账时间</div>
						<div class="field">
							<input name="fReceivedTm" id="fReceivedTm" type="text" class="ui-datepicker" value="" validate="{required:false}">
							<span class="requiredSymbol">*</span>
						</div>
					</div>
					<div class="fieldBox col_50 cwqr">
						<div class="label">到账金额(元)</div>
						<div class="field">
							<input name="fReceivedAmt" id="fReceivedAmt" type="text" class="ui-textbox" value="${recAmtVo.receivedAmt / 100}" validate="{required:false}">
							<span class="requiredSymbol">*</span>
						</div>
					</div>
					<div class="fieldBox col_50 syje">
						<div class="label">使用金额(元)</div>
						<div class="field">
							<input name="useAmt" id="useAmt" type="text" class="ui-textbox" value="${recAmtVo.useAmt /100}" validate="{required:false}">
							<span class="requiredSymbol">*</span>
						</div>
					</div>
    			</div>
				<div class="btnsBox">
					<span id="saveRecAmtBtn" class="sq-button sq-button-round">保存</span>
					<input type="reset" id="resetBtn" class="l-button l-button-reset Hide">
   				</div>
			</form>
		</div>
	</div>
	<script type="text/javascript">
	 $(function () {
	        $("#recAmtInfo").ligerForm({
	            validate: true
	        });
			//加载表单
			if('${recAmtVo.receivedTm}' !=''){//到账时间
		    	liger.get("recAmtInfo").setData({
					fReceivedTm: renderDate1('${recAmtVo.receivedTm}')
		    	});
			}
			if('${recAmtVo.payTm}' !=''){//付款时间
		    	liger.get("recAmtInfo").setData({
		    		payTm: renderDate1('${recAmtVo.payTm}')
		    	});
			}
			//加载日期插件
			$("#payTm").trigger("change");
			$("#fReceivedTm").trigger("change");
			//数据类型不可编辑
			if('${goFlag}' == '1'){//赎回
				liger.get("recAmtInfo").setData({
					dataTypeCd: '2'
		    	});
			}else if('${goFlag}' == '4'){//拖车
				liger.get("recAmtInfo").setData({
					dataTypeCd: '3'
		    	});
			}else if('${goFlag}' == '3'){//处置
                liger.get("recAmtInfo").setData({
                    dataTypeCd: '1'
                });
            }else{
				liger.get("recAmtInfo").setData({
					dataTypeCd: '1'
		    	});
			}
			liger.get("dataTypeCd").setDisabled(true);
			// 使用金额默认不展示，只在固定的节点展示
			//liger.get("useAmt").setDisabled(true);
		    $(".syje").addClass('Hide');

	        //设置字段编辑状态
		 	// dataTypeCd（处置收款-数据类型）：1-处置，2-赎回，3-拖车
		    // n个流程的处置，都会走这个页面，所以flag在不同流程中的节点定义是不一样的
		    // flag（优车处置流程节点）: 1-销售总监审批，2-发起人， 3-事业部总经理审批，4-销售合同签署通知打款，5-商助合同复核，6-账务部确认来款，
		 	//                 7-呈报人添加提车人信息，8-资产管理员出库登记， 9-系统管理员审核出库， 10-运营提报费用，11-财务做帐
		 	// flag（拖车管理处置节点）：
			var dataTypeCd = $("#dataTypeCd").val();
         	console.log("编辑付款页面："+dataTypeCd+" | "+'${flag}');
	        if((dataTypeCd == '2' && '${flag}' == '5') || (dataTypeCd == '1' && ('${flag}' == '7' || '${flag}' == '4' || '${flag}' == '18'))){//发起人通知打款
	        	if((dataTypeCd == '2' && '${flag}' == '5') || '${flag}' == '7') {
					//拖车赎回流程-发起人通知打款,"使用金额"展示 或 拖车管理处置流程-发起人通知打款,"使用金额"展示
					//liger.get("useAmt").setDisabled(false);
					$(".syje").removeClass('Hide');
					var formSet=liger.get("recAmtInfo");
					formSet.setFieldValidate("useAmt", {required: true});
				}
				if (dataTypeCd == '1' && ('${flag}' == '4')){
	        	    // 优车处置
                    $(".syje").removeClass('Hide');
					var formSet=liger.get("recAmtInfo");
					formSet.setFieldValidate("useAmt", {required: true});
				}

				$(".cwqr").addClass('Hide');//隐藏到账信息
	        	liger.get("fReceivedTm").setDisabled(true);//到账时间
	        	liger.get("fReceivedAmt").setDisabled(true);//到账金额
	        	var formSet=liger.get("recAmtInfo");
	        	formSet.setFieldValidate("payTm", {required: true});
	        }else if((dataTypeCd == '2' && '${flag}' == '6') || (dataTypeCd == '1' && ('${flag}' == '8' || '${flag}' == '6'))){//财务确认付款
				if((dataTypeCd == '2' && '${flag}' == '6') || '${flag}' == '8') {
					//拖车赎回流程-财务确认付款,"使用金额"展示 或者 拖车管理处置流程-财务确认付款,"使用金额"展示
					$(".syje").removeClass('Hide');
					var formSet=liger.get("recAmtInfo");
					formSet.setFieldValidate("useAmt", {required: true});
				}
                if (dataTypeCd == '1' && ('${flag}' == '6')){
                    // 优车处置
                    $(".syje").removeClass('Hide');
					var formSet=liger.get("recAmtInfo");
					formSet.setFieldValidate("useAmt", {required: true});
                }

	        	$(".cwqr").removeClass('Hide');//显示到账信息
	        	liger.get("dataTypeCd").setDisabled(true);//数据类型
	        	liger.get("payerBankNm").setDisabled(true);//银行信息
	        	liger.get("payerAccNo").setDisabled(true);//账号信息
	        	liger.get("payerAccNm").setDisabled(true);//付款方名称
	        	liger.get("payAmt").setDisabled(true);//付款金额
	        	liger.get("payTm").setDisabled(true);//付款时间
	        	var formSet1=liger.get("recAmtInfo");
	        	formSet1.setFieldValidate("fReceivedTm", {required: true});
	        	formSet1.setFieldValidate("fReceivedAmt", {required: true});
	        }else if(dataTypeCd == '3' && ('${flag}' == '8' || '${flag}' == '12')){
	        	$(".cwqr").addClass('Hide');//隐藏到账信息
	        	liger.get("fReceivedTm").setDisabled(true);//到账时间
	        	liger.get("fReceivedAmt").setDisabled(true);//到账金额
	        	var formSet=liger.get("recAmtInfo");
	        	formSet.setFieldValidate("payTm", {required: true});
	        }
	        
	        //保存：新增-修改
	        $("#saveRecAmtBtn").click(function (event) {
	            var form = liger.get("recAmtInfo");
	            if (!form.valid()) {
	                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
	                return false; //验证不通过，不执行以下代码
	            }

				//校验“使用金额”不得超过“来款金额”
				var useAmt = $("#useAmt").val();
				var payAmt = $("#payAmt").val();
				//alert("useAmt:" + useAmt + ";payAmt:" + payAmt);
				if(useAmt != null && useAmt != '') {
					if(parseFloat(useAmt) > parseFloat(payAmt)) {
						$.ligerDialog.SQalert({content: "使用金额不能大于付款金额！", SQ_type: "warning"});
						return false; //验证不通过，不执行以下代码
					}
				}

	            var data = form.getData();
	            data["dataId"] = "${dataId}";
	            data["assDealRecAmt_id"] = "${assDealRecAmt_id}";
	            data["goFlag"] = "${goFlag}";
	            $.ligerDialog.hide();
	            var _url = '<%=path%>/ass/assTrailCarD/updateYCDealInfo.do';
	            var wait_dialog = null;
	            $.ajax({
	                type: 'post',
	                dataType: 'json',
	                data: data,
	                url: _url,
	                beforeSend: function () {
	                    wait_dialog = top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
	                },
	                success: function (msg) {
	                    wait_dialog.close();
	                    if (msg.success == 1) {
	                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
	                        if('${goFlag}' == '1'){//拖车赎回
	                        	parent.window.location.href="<%=path%>/ass/assTrailCarD/toRedeemViewPage.do?flag="+${flag}+"&redeem_Id="+${dataId};
								//parent.grid.reload();
	                        }else if('${goFlag}' == '2'){//拖车管理处置
	                        	parent.window.location.href="<%=path%>/ass/assTrailCarD/toDealViewPage.do?flag="+${flag}+"&deal_Id="+${dataId};
	                        }if('${goFlag}' == '3'){//优车处置
	                        	parent.window.location.href="<%=path%>/ass/assTrailCarD/toYCDealViewPage.do?flag="+${flag}+"&yc_deal_Id="+${dataId};
	                        }if('${goFlag}' == '4'){//拖车
	                        	parent.window.location.href="<%=path%>/ass/assTrailCarM/toViewPage.do?flag="+${flag}+"&tcMasterId="+${dataId};
	                        }
	                        frameElement.dialog.close();
	                    } else {
	                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
	                    }
	                }
	            });
	        });
	    });

	</script>
</body>
</html>